package com.example.service;

import cn.hutool.core.date.DateUtil;

import com.example.entity.Family;

import com.example.mapper.FamilyMapper;

import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FamilyService {
    @Resource
    private FamilyMapper familyMapper;

    /**
     * 新增
     */
    public void add(Family family) {
        family.setTime(DateUtil.today());

        familyMapper.insert(family);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        familyMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            familyMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(Family family) {
        family.setTime(DateUtil.today());
       familyMapper.updateById(family);
    }

    /**
     * 根据ID查询
     */
    public Family selectById(Integer id) {

        return familyMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<Family> selectAll(Family family) {
        return familyMapper.selectAll(family);
    }

    /**
     * 分页查询
     */
    public PageInfo<Family> selectPage(Family family, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Family> list = familyMapper.selectAll(family);
        return PageInfo.of(list);
    }

}
